from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_page import BasePage

class ContactsEditPage(BasePage):
    """合同编辑页面做的操作"""
    click_commercial_locator = (By.CSS_SELECTOR, '#business_name')
    select_commercial_locator = (By.NAME, 'business')
    click_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    select_principal_locator = (By.XPATH, '//*[@id="owner_name"]')
    select_frist_locator = (By.XPATH, '//*[@id="d_content"]/tr[1]/td[1]/input')
    click_edit_ok_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]/span')
    click_save_locator = (By.CSS_SELECTOR,'#tab1 > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary')
    edit_successful_tips_locator=(By.CSS_SELECTOR,'#tab1 > div.back_box > div')
    select_state_locator = (By.CSS_SELECTOR, '#status')
    edit_contract_number_locator = (By.CSS_SELECTOR, '#number')

    def click_edit_commercial(self):
        """点击商机"""
        self.driver.find_element(*self.click_commercial_locator).click()

    def select_edit_commercial(self):
        """选择商机"""
        self.driver.find_element(*self.select_commercial_locator).click()

    def click_edit_commercial_ok(self):
        """点击商业ok"""
        self.driver.find_element(*self.click_ok_locator).click()

    def edit_principal_first(self):
        """点击修改负责人"""
        self.driver.find_element(*self.select_principal_locator).click()

    def select_first_principal(self):
        """选择第一个负责人"""
        self.driver.find_element(*self.select_frist_locator).click()

    def click_edit_ok(self):
        """点击ok"""
        self.driver.find_element(*self.click_edit_ok_locator).click()

    def click_edit_save(self):
        """点击保存"""
        self.driver.find_element(*self.click_save_locator).click()

    def edit_successful_tips(self):
        """断言"""
        edit_tips=self.driver.find_element(*self.edit_successful_tips_locator).text
        return edit_tips


    def select_stage_first(self):
        """状态选择下拉框第一个"""
        self.select_state_element=self.driver.find_element(*self.select_state_locator)
        select = Select(self.select_state_element)
        select.select_by_value('已批准')

    def edit_contract_number(self,contract_number):
        """修改合同编号"""
        self.edit_contract_number_element = self.driver.find_element(*self.edit_contract_number_locator)
        self.edit_contract_number_element.clear()
        self.edit_contract_number_element.send_keys(contract_number)

